﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StatusPlan3.UC
{
    /// <summary>
    /// Interaction logic for UCMessageWithReply.xaml
    /// </summary>
    public partial class UCMessageWithReply : UserControl
    {
        public Message message;
        public UCMessages ucMessages;

        public UCMessageWithReply()
        {
            InitializeComponent();
        }

        public UCMessageWithReply(Message m, UCMessages ucm)
        {
            ucMessages = ucm;
            message = m;
            InitializeComponent();
            setData(m);
        }

        public void setData(Message orgM)
        {
            message = orgM;
            radExpander1.Header = message.sender.fullName + ": " + message.subject + "(" + message.createdDate.ToString("dd-MM-yyyy HH:mm") + ")";

            ContentStackPanel.Children.Add(new UC.UCMessage(message));
            if (message.replies.Count > 0)
            {
                radExpander1.Header += " (" + message.replies.Count + ")";

                var repliesOrderByDate = (from m2 in message.replies orderby m2.createdDate ascending select m2);

                foreach (Message m in repliesOrderByDate)
                {
                    UC.UCMessage ucMessage = new UC.UCMessage(m);
                    ucMessage.Margin = new Thickness(20, 5, 0, 0);
                    ucMessage.message = message;
                    ucMessage.isReply();

                    ContentStackPanel.Children.Add(ucMessage);
                }
            }

            UC.UCMessage ucMessage2 = new UC.UCMessage();
            ucMessage2.message = message;
            ucMessage2.Margin = new Thickness(20, 5, 0, 0);
            ucMessage2.ucMessages = ucMessages;
            ucMessage2.isMyReply();

            ContentStackPanel.Children.Add(ucMessage2);
        }
    }
}
